package com.thinktank.controller;

import static com.thinktank.util.DbUtil.*;

import java.io.*;
import java.sql.*;
import java.util.*;

import javax.servlet.*;
import javax.servlet.http.*;

import com.oreilly.servlet.*;
import com.oreilly.servlet.multipart.*;
import com.thinktank.vo.Board;
import com.thinktank.vo.Reply;
import com.thinktank.dao.BoardDao;

public class BoardReplyRegProcessController implements Controller{
	public String execute(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		
		request.setCharacterEncoding("utf-8");
		String rWriter = request.getParameter("rWriter");
		String rContent = request.getParameter("rContent");
		String bNo = request.getParameter("bNo");
		
		// bContent 엔터 허용
		rContent = rContent.replaceAll("\r\n", "<br />");
		
		Reply reply = new Reply();
		
		reply.setrWriter(rWriter);
		reply.setrContent(rContent);
		
		Connection con = getConnection();
		BoardDao dao = new BoardDao(con);
		int result = dao.insert(reply, bNo);
		
		close(con);
		
		if(result == 0) {
			return "error.jsp";
		}
		
		return "redirect:boardDetail.do?bNo=" + bNo;
		
	}
}
